import type { ModalProps } from 'ant-design-vue';

import useForm, { type IUseFormArg } from './useForm';

/**
 * 弹窗组件公共方法
 * @param options form 表单组件ElForm实例引用; validCallback 表单校验成功回调
 */
export default function useDialog(useFormArg: IUseFormArg) {
  const attrs = useAttrs() as ModalProps;
  /**
   * 关闭弹窗
   */
  function close() {
    attrs['onUpdate:visible'] && attrs['onUpdate:visible'](false);
  }

  return {
    attrs,
    close,
    ...useForm(useFormArg)
  };
}
